package top.kaoshanji.p3ch21a;

import java.util.ArrayList;

/**
 * 代码清单-p3ch21a-242页a：根节点的实现
 * @author kaoshanji
 * ^_^
 * create time 2025/3/25 21:11
 */
public class Root implements IRoot {

    // 保存根节点下的树枝节点和树叶节点， Subordinate 的意思是下级
    private ArrayList subordinateList = new ArrayList();

    // 根节点的名称
    private String name = "";

    // 根节点的职位
    private String position = "";

    // 根节点的薪水
    private int salary = 0;

    // 通过构造函数传递进来总经理的信息
    public Root(String name, String position, int salary) {
        this.name = name;
        this.position = position;
        this.salary = salary;
    }

    @Override
    public String getInfo() {
        return "名称： " + this.name + "\t 职位： " + this.position + "\t 薪水： " + this.salary;
    }

    @Override
    public void add(IBranch branch) {
        this.subordinateList.add(branch);
    }

    @Override
    public void add(ILeaf leaf) {
        this.subordinateList.add(leaf);
    }

    @Override
    public ArrayList getSubordinateInfo() {
        return this.subordinateList;
    }
}
